package com.shr.lease.web.admin.config;

import com.shr.lease.web.admin.custom.converter.StringTOBaseEnumConverterFactory;
import com.shr.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Haoran Sun
 * @since 2024/06/14
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    /*    @Resource
        private StringToItemTypeConverter stringToItemTypeConverter;
    */

    @Resource
    private StringTOBaseEnumConverterFactory stringTOBaseEnumConverterFactory;
    @Resource
    private AuthenticationInterceptor authenticationInterceptor;

    /**
     * 注册枚举和code的工厂转化器
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringTOBaseEnumConverterFactory);
    }

    /**
     * 注册登录拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .excludePathPatterns("/admin/login/**")
                .addPathPatterns("/admin/**");
    }
}
